#ifndef _IM_SERVER_COMET_SUBSCRIBE_REQUEST_
#define _IM_SERVER_COMET_SUBSCRIBE_REQUEST_

#include "http_request.h"

namespace imserver {

class CometSubscribeRequest : public HttpRequest {
 public:
  CometSubscribeRequest(CometConnectionPtr conn, const std::string & data)
    : HttpRequest(conn, data) {
    ++ctor_count_;
  }

  virtual ~CometSubscribeRequest() {}
  virtual int OnMessageReady(const std::vector<ImMessage> &messages);
  virtual int OnCheckTicketComplete(int64_t qid, const std::string & username);

  virtual void OnReadError();
  virtual void OnWriteError();
  virtual void OnWriteComplete();

  static int64_t ctor_count_;
  static int64_t out_messages_;
 private:
  virtual bool Response();

  void AsyncWaitForMessage();

  int UserLoginResponse(bool is_access_switch);
  int HostSwitchResponse();
  virtual int DuplicateErrorResponse();
  int IeBugFixResponse();

  void AddLingerSession();

  std::string username_;
};

}

#endif // _IM_SERVER_COMET_SUBSCRIBE_REQUEST_
